const { lessorsModel } = require("./models/lessorsModel");
const { adminsModel } = require('./models/adminsModel');
const { tenantsModel } = require('./models/tenantsModel');

//出租方账号注册==============================================================
//验证账号是否存在
module.exports.isAccess = async function (account) {
    //判断是出租方
    if (account.radio == "lessors") {
        const data = lessorsModel.find({ account: account.account });
        return data;
    } else {
        const data = adminsModel.find({ account: account.account });
        return data;
    }
}

//注册
module.exports.register = async function (power) {
    // console.log('数据', lessors)
    //判断是出租方
    if (power.radio == "lessors") {
        const data = lessorsModel.create({ account: power.account, password: power.password, phone: power.phone });
        return data;
    } else {
        const data = adminsModel.create({ account: power.account, password: power.password, phone: power.phone });
        return data;
    }
}

// 登录
module.exports.login = async function (power) {
    //判断如果是出租方
    if (power.radio == 'lessors') {
        const data = lessorsModel.find({ account: power.account, password: power.password });
        return data;
    } else {
        const data = adminsModel.find({ account: power.account, password: power.password });
        return data;
    }
}


//验证租客账号是否存在
module.exports.isHave = async function (account) {
    const data = tenantsModel.find({ account: account });
    return data;
}

// 租客注册
module.exports.registers = async function (power) {
    const data = tenantsModel.create({ account: power.account, password: power.password, phone: power.phone, name: power.name, IDCard: power.Idcard });
    return data;
}


// 登录
module.exports.logins = async function (power) {

    const data = tenantsModel.find({ account: power.account, password: power.password });
    return data;
}